//
//  SearchTableViewCell.m
//  MountEverestFM
//
//  Created by ChenNing on 15/11/5.
//  Copyright © 2015年 chenn. All rights reserved.
//

#import "CommonSearchTableViewCell.h"
#import "CommonSearchCollectionViewCell.h"
@implementation CommonSearchTableViewCell
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self=[super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.flowLayout=[[UICollectionViewFlowLayout alloc]init];
        self.flowLayout.itemSize=CGSizeMake(FM_Screen_Pts_Width*100, FM_Screen_Pts_Height*40);
        
        self.flowLayout.sectionInset=UIEdgeInsetsMake(0, 10, 0, 10);
        
        self.collection=[[UICollectionView alloc]initWithFrame:self.contentView.bounds collectionViewLayout:self.flowLayout];
        self.collection.delegate=self;
        self.collection.dataSource=self;
        [self.contentView addSubview:self.collection];
        
        [self.collection registerClass:[CommonSearchCollectionViewCell class] forCellWithReuseIdentifier:@"feijin"];
    }
    return self;
}

-(void)layoutSubviews
{
    [super layoutSubviews];
    self.collection.frame=CGRectMake(0, 0, FM_Screen_Width, self.contentView.frame.size.height);
    self.collection.backgroundColor=[UIColor whiteColor];
    
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return self.arr.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    CommonSearchCollectionViewCell *cell=[collectionView dequeueReusableCellWithReuseIdentifier:@"feijin" forIndexPath:indexPath];
    cell.lable.text=[self.arr objectAtIndex:indexPath.item];
    
    
    return cell;
}

-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    self.block([self.arr objectAtIndex:indexPath.item]);
}

- (void)setArr:(NSArray *)arr
{
    if (_arr != arr) {
        _arr = arr;
    }
    [self.collection reloadData];
}
@end
